package volatileT;

import java.util.concurrent.CountDownLatch;

/**
 *
 * volatile关键字练习
 *
 * Created by zhoub on 2022/3/7.
 */
public class VolatileDemo {

//    private static int number = 0;
    private static volatile int number = 0;

    public static void main(String[] args){

        Thread generator = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Thread1 Count :: "+number);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                number++;
            }
        });
        Thread printer = new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    if(number == 1){
                        System.out.println("Thread2 Count :: "+number);
                    }
                }
            }
        });
        generator.start();
        printer.start();


    }
}
